import React, { useState } from 'react';
import { SearchOutlined, ReloadOutlined } from '@ant-design/icons';
import { Form, Input, Button, message } from 'antd';
import {
  VendorSelect,
} from '@/components/FormItemSelect';
import { useIntl, FormattedMessage } from 'umi';
export interface SelectProps {
  defaultParams: {};
  onSearch: (values: any) => void;
  children: any;
  // hideSearchForm: any;
}
const SearchForm: React.FC<SelectProps> = (props: SelectProps) => {
  const [fold, setFold] = useState(true);
  const [form] = Form.useForm();
  const intl = useIntl();
  const search = (values: any) => {
    if (typeof props.onSearch === 'function') {
      props.onSearch(values);
    }
  };
  const handleReset = () => {
    form.resetFields();
    message.success(intl.formatMessage({ id: 'pages.reset.success' }));
  };
  return (
    <Form form={form} layout="inline" initialValues={props.defaultParams} onFinish={search}>
      <VendorSelect
        showSearch={true}
        width={150}
        name='vendorNum'
        placeholder={<FormattedMessage id="pages.vendor.select" />}
        label={<FormattedMessage id="pages.vendor" />}
      />
      <Form.Item name="partNum" label={<FormattedMessage id="pages.partNum" />}>
        <Input placeholder={intl.formatMessage({ id: 'pages.partNum' })} />
      </Form.Item>
      <Form.Item>
        <Button.Group>
          <Button
            type="primary"
            icon={<SearchOutlined />}
            htmlType="submit"
          >
            <span><FormattedMessage id="pages.search" /></span>
          </Button>
          <Button icon={<ReloadOutlined />} onClick={handleReset}>
            <span><FormattedMessage id="pages.reset" /></span>
          </Button>
        </Button.Group>
        {props.children}
      </Form.Item>

    </Form>
  );
};

export default SearchForm;
